<template>
  <el-form :model="form" label-position="top">
    <el-form-item label="单元格名称">
      <el-input ref="startRegionInput" v-model="form.startRegion" @change="change" @focus="focus"/>
    </el-form-item> 
    <el-form-item label="数据集id">
      <el-input v-model="form.id" />
    </el-form-item>
    <el-form-item label="表名">
      <el-input v-model="form.tableName" />
    </el-form-item>
    <el-form-item label="表关联类型">
      <el-select v-model="form.relationType" clearable placeholder="请选择：">
        <el-option
          v-for="item in configData.relationTypeList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="关联主表名">
      <el-input v-model="form.parentTableId" />
    </el-form-item>
    <el-form-item label="记录相同的字段">
      <el-input v-model="form.uniqueFields" />
    </el-form-item>
    <el-form-item label="导入单条记录后触发事件">
      <el-input v-model="form.importRecordActions" type="textarea"/>
    </el-form-item>
    <el-form-item label="导入所有记录后触发事件">
      <el-input v-model="form.importTableActions" />
    </el-form-item>
    <el-form-item label="更新条件的sql语句">
      <ts-code-editor
        style="width: 100%"
        v-model="form.updateConditionSql"
        :height="300"
      ></ts-code-editor>
    </el-form-item>
    <el-form-item label="判断记录是否存在的sql语句">
      <ts-code-editor
        style="width: 100%"
        v-model="form.existRecordSql"
        :height="300"
      ></ts-code-editor>
    </el-form-item>
    <el-form-item label="sql类型">
      <el-select v-model="form.dataset.dsType" clearable placeholder="请选择：">
        <el-option
          v-for="item in configData.dsTypeList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="sql">
      <ts-code-editor
        style="width: 100%"
        v-model="form.dataset.sql"
        :height="300"
      ></ts-code-editor>
    </el-form-item>
  </el-form>
</template>
<script setup>
import { ref, defineModel,watch } from "vue";
import { ElMessage } from "element-plus";
import tsCodeEditor from '@/components/scCodeEditor/index.vue'
const emit = defineEmits(['changeRange'])
const form = defineModel();
const oldStartRegion = ref()
const props = defineProps({
  configData:{type:Array,default:[]}
})
const focus = () =>{
  oldStartRegion.value = form.value.startRegion
}
const change = (val)=>{
  const regex = /^[A-Z]+[0-9]+$/
  if(regex.test(val)){
    emit('changeRange',{newValue:val,oldValue:oldStartRegion.value})
  }
  else{
    ElMessage({
    message: '输入格式不符合',
    type: 'warning',
  })
  }
}
</script>
